/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.yuhanginfo.modules.sys.web;



import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.modules.sys.entity.Dict;
import com.yuhanginfo.modules.sys.entity.Goods;
import com.yuhanginfo.modules.sys.entity.User;
import com.yuhanginfo.modules.sys.service.GoodsStoreExamineService;
import com.yuhanginfo.modules.sys.utils.DictUtils;
import com.yuhanginfo.modules.sys.utils.UserUtils;

/**
 * 门店商品信息审核Controller
 * 
 * @author yinhao
 * @version 2017-10-9
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/goodsstoreexamine/")
public class GoodsStoreExamineController extends BaseController {

	@Autowired
	private  GoodsStoreExamineService goodsStoreExamineService;
	
	@ModelAttribute
	public Goods get(@RequestParam(required = false) String id) {
		Goods entity = null;
		if (StringUtils.isNotBlank(id)) {
			entity = goodsStoreExamineService.get(id);
		}
		if (entity == null) {
			entity = new Goods();
		}
		return entity;
	}

	@RequiresPermissions("sys:goodsstoreexamine:view")
	@RequestMapping(value = { "list", "" })
	public String list(Goods goods, HttpServletRequest request, HttpServletResponse response, Model model) {
		if(goods.getCreateBy() == null){
			User user = UserUtils.getUser();
			goods.setCreateBy(user);
		}
		Page<Goods> page = goodsStoreExamineService.findPage(new Page<Goods>(request, response), goods);
		//商品审核状态
		List<Dict> goodsExamineStatusList = DictUtils.getDictList("goods_examine_status");
		//商品来源
		List<Dict> goodsourceList = DictUtils.getDictList("goods_source");
		model.addAttribute("goodsExamineStatusList", goodsExamineStatusList);
		model.addAttribute("goodsourceList", goodsourceList);
		model.addAttribute("page", page);
		return "modules/sys/goodsstoreexamine/goodsstoreexamineList";
	}

	@RequiresPermissions("sys:goodsstoreexamine:edit")
	@RequestMapping(value = "save")
	public String save(Goods goods, Model model, HttpServletRequest request, HttpServletResponse response) {
		goodsStoreExamineService.save(UserUtils.getUser(), goods);
		return this.list(goods, request, response, model);
	}

}